home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
a_utils
/
expanded.lha
/
expanded
/
src
/
Scalar.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-19
|
4KB
|
165 lines
//
// Linear-Affine-Projective Geometry Package
//
// Scalar.C
//
// $Header$
//
// William J.R. Longabaugh
// University of Washington
//
// Implementation of the linear-affine-projective geometry
// package described in William J.R. Longabaugh, "An Expanded
// System for Coordinate-Free Geometric Programming", Master's
// thesis, University of Washington, 1992.
//
// Copyright (c) 1992, William J.R. Longabaugh
// Copying, use and development for non-commercial purposes permitted.
// All rights for commercial use reserved.
// This software is unsupported and without warranty; it is
// provided "as is".
//
// ***********************************************************************
#include "Lap.h"
// ***********************************************************************
// ***********************************************************************
//
// AugScalar Class
//
// ***********************************************************************
// ***********************************************************************
//
// Public member functions
//
// ***********************************************************************
//
// Default augmented scalar equals 0.0:
//
AugScalar::AugScalar(void) : m(1, 2)
{
is_inf = FALSE;
m[0][0] = 0.0;
m[0][1] = 1.0;
}
// ***********************************************************************
//
// Create an augmented scalar with a finite value:
//
AugScalar::AugScalar(Scalar v) : m(1, 2)
{
is_inf = FALSE;
m[0][0] = v;
m[0][1] = 1.0;
}
// ***********************************************************************
//
// Create an augmented scalar with the value INFINITY:
//
AugScalar::AugScalar(Infnum n) : m(1, 2)
{
if (n == INFINITY) {
is_inf = TRUE;
} else {
errh.ErrorExit("AugScalar::AugScalar(Infnum)",
"Illegal value for building augmented scalar",
ErrVal("Value of argument = ", n));
}
m[0][0] = 1.0;
m[0][1] = 0.0;
}
// ***********************************************************************
//
// Automatically cast an augmented scalar into a scalar:
//
AugScalar::operator Scalar()
{
if (!is_inf) {
return (m[0][0] / m[0][1]);
} else {
errh.ErrorExit("AugScalar::operator Scalar()",
"Attempted to cast INFINITY to a scalar");
}
}
// ***********************************************************************
//
// Get the value of the augmented scalar (This is just an explicit form of
// casting to a scalar).
//
Scalar AugScalar::Value(void)
{
if (!is_inf) {
return (m[0][0] / m[0][1]);
} else {
errh.ErrorExit("Scalar AugScalar::Value(void)",
"INFINITE augmented scalar cannot return a value");
}
}
// ***********************************************************************
//
// Need to do memberwise initialization, since Matrix class members need
// to do memberwise initialization:
//
AugScalar::AugScalar(AugScalar& a) : m(a.m)
{
is_inf = a.is_inf;
}
// ***********************************************************************
//
// Need to do memberwise assignment, since Matrix class members need
// to do memberwise assignment:
//
AugScalar& AugScalar::operator=(AugScalar& a)
{
is_inf = a.is_inf;
m = a.m;
return (*this);
}
// ***********************************************************************
void AugScalar::debug_out(ostream& c, int indent)
{
char *ibloc = new char[indent + 1];
for (int i = 0; i < indent; i++) {
*(ibloc + i) = ' ';
}
*(ibloc + indent) = '\0';
c << ibloc << ast;
c << ibloc << "Augmented scalar object\n";
if (is_inf) {
c << ibloc << "Value = INFINITY\n";
} else {
c << ibloc << "Value = " << (m[0][0] / m[0][1]) << "\n";
}
c << ibloc << ast;
delete ibloc;
return;
}
// ***********************************************************************